package main

import (
	"github.com/lonng/nano"
	"github.com/lonng/nano/component"
	"github.com/lonng/nano/pipeline"
	"github.com/lonng/nano/serialize/json"
	"log"
	"nano_chatRoom/utils"
	"net/http"
	"strings"
)

func main(){
	components := &component.Components{}
	components.Register(
		utils.NewRoomManager(),
		component.WithName("room"),//rewrite component and handler name
		component.WithNameFunc(strings.ToLower),
	)
	// traffic stats
	pip := pipeline.New()
	var stats = &utils.State{}
	pip.Outbound().PushBack(stats.Outbound)
	pip.Inbound().PushBack(stats.InBound)

	log.SetFlags(log.LstdFlags | log.Llongfile)
	http.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir("../deploy"))))

	nano.Listen(":3250",
		nano.WithIsWebsocket(true),
		nano.WithPipeline(pip),
		nano.WithCheckOriginFunc(func(_ *http.Request)bool{ return true}),
		nano.WithWSPath("/nano"),
		nano.WithDebugMode(),
		nano.WithSerializer(json.NewSerializer()),
		nano.WithComponents(components),
	)
}